package com.qdu.hyy;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class MovieWritable implements Writable, WritableComparable<MovieWritable> {


    private String id;
    private String title;


    private String tagline;
    private String release_date;
    private String genres;
    private String belongs_to_collection;
    private String original_language;
    private double budget_musd;
    private double revenue_musd;
    private String production_companies;
    private String production_countries;
    private int vote_count;
    private double vote_average;
    private double popularity;
    private int runtime;
    private String overview;
    private String spoken_languages;
    private String poster_path;
    private String cast;
    private int cast_size;
    private int crew_size;
    private String director;

    public MovieWritable(){

    }

    public MovieWritable(String id, String title, String tagline, double vote_average) {
        this.id = id;
        this.title = title;
        this.tagline = tagline;
        this.vote_average = vote_average;
    }

    public MovieWritable(String id, String title, String tagline, String release_date, String genres,
                         String belongs_to_collection, String original_language,
                         double budget_musd, double revenue_musd, String production_companies,
                         String production_countries, int vote_count, double vote_average,
                         double popularity, int runtime, String overview, String spoken_languages,
                         String poster_path, String cast, int cast_size, int crew_size, String director) {
        this.id = id;
        this.title = title;
        this.tagline = tagline;
        this.release_date = release_date;
        this.genres = genres;
        this.belongs_to_collection = belongs_to_collection;
        this.original_language = original_language;
        this.budget_musd = budget_musd;
        this.revenue_musd = revenue_musd;
        this.production_companies = production_companies;
        this.production_countries = production_countries;
        this.vote_count = vote_count;
        this.vote_average = vote_average;
        this.popularity = popularity;
        this.runtime = runtime;
        this.overview = overview;
        this.spoken_languages = spoken_languages;
        this.poster_path = poster_path;
        this.cast = cast;
        this.cast_size = cast_size;
        this.crew_size = crew_size;
        this.director = director;
    }

    @Override
    public String toString() {
        return "MovieWritable{" +
                "id='" + id + '\'' +
                ", title='" + title + '\'' +
                ", tagline='" + tagline + '\'' +
                ", release_date='" + release_date + '\'' +
                ", genres='" + genres + '\'' +
                ", belongs_to_collection='" + belongs_to_collection + '\'' +
                ", original_language='" + original_language + '\'' +
                ", budget_musd=" + budget_musd +
                ", revenue_musd=" + revenue_musd +
                ", production_companies='" + production_companies + '\'' +
                ", production_countries='" + production_countries + '\'' +
                ", vote_count=" + vote_count +
                ", vote_average=" + vote_average +
                ", popularity=" + popularity +
                ", runtime=" + runtime +
                ", overview='" + overview + '\'' +
                ", spoken_languages='" + spoken_languages + '\'' +
                ", poster_path='" + poster_path + '\'' +
                ", cast='" + cast + '\'' +
                ", cast_size=" + cast_size +
                ", crew_size=" + crew_size +
                ", director='" + director + '\'' +
                '}';
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }


    public String getTagline() {
        return tagline;
    }

    public void setTagline(String tagline) {
        this.tagline = tagline;
    }

    public String getRelease_date() {
        return release_date;
    }

    public void setRelease_date(String release_date) {
        this.release_date = release_date;
    }

    public String getGenres() {
        return genres;
    }

    public void setGenres(String genres) {
        this.genres = genres;
    }

    public String getBelongs_to_collection() {
        return belongs_to_collection;
    }

    public void setBelongs_to_collection(String belongs_to_collection) {
        this.belongs_to_collection = belongs_to_collection;
    }

    public String getOriginal_language() {
        return original_language;
    }

    public void setOriginal_language(String original_language) {
        this.original_language = original_language;
    }

    public double getBudget_musd() {
        return budget_musd;
    }

    public void setBudget_musd(double budget_musd) {
        this.budget_musd = budget_musd;
    }

    public double getRevenue_musd() {
        return revenue_musd;
    }

    public void setRevenue_musd(double revenue_musd) {
        this.revenue_musd = revenue_musd;
    }

    public String getProduction_companies() {
        return production_companies;
    }

    public void setProduction_companies(String production_companies) {
        this.production_companies = production_companies;
    }

    public String getProduction_countries() {
        return production_countries;
    }

    public void setProduction_countries(String production_countries) {
        this.production_countries = production_countries;
    }

    public int getVote_count() {
        return vote_count;
    }

    public void setVote_count(int vote_count) {
        this.vote_count = vote_count;
    }

    public double getVote_average() {
        return vote_average;
    }

    public void setVote_average(double vote_average) {
        this.vote_average = vote_average;
    }

    public double getPopularity() {
        return popularity;
    }

    public void setPopularity(double popularity) {
        this.popularity = popularity;
    }

    public int getRuntime() {
        return runtime;
    }

    public void setRuntime(int runtime) {
        this.runtime = runtime;
    }

    public String getOverview() {
        return overview;
    }

    public void setOverview(String overview) {
        this.overview = overview;
    }

    public String getSpoken_languages() {
        return spoken_languages;
    }

    public void setSpoken_languages(String spoken_languages) {
        this.spoken_languages = spoken_languages;
    }

    public String getPoster_path() {
        return poster_path;
    }

    public void setPoster_path(String poster_path) {
        this.poster_path = poster_path;
    }

    public String getCast() {
        return cast;
    }

    public void setCast(String cast) {
        this.cast = cast;
    }

    public int getCast_size() {
        return cast_size;
    }

    public void setCast_size(int cast_size) {
        this.cast_size = cast_size;
    }

    public int getCrew_size() {
        return crew_size;
    }

    public void setCrew_size(int crew_size) {
        this.crew_size = crew_size;
    }

    public String getDirector() {
        return director;
    }

    public void setDirector(String director) {
        this.director = director;
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {

        Text.writeString(dataOutput, id);
        Text.writeString(dataOutput, title);
        Text.writeString(dataOutput, tagline);
        try {
            Text.writeString(dataOutput, release_date);
        }catch (Exception e){
            e.printStackTrace();
        }

        Text.writeString(dataOutput, genres);
        Text.writeString(dataOutput, belongs_to_collection);
        Text.writeString(dataOutput, original_language);
        dataOutput.writeDouble(budget_musd);
        dataOutput.writeDouble(revenue_musd);
        Text.writeString(dataOutput, production_companies);
        Text.writeString(dataOutput, production_countries);
        dataOutput.writeInt(vote_count);
        dataOutput.writeDouble(vote_average);
        dataOutput.writeDouble(popularity);
        dataOutput.writeInt(runtime);
        Text.writeString(dataOutput, overview);
        Text.writeString(dataOutput, spoken_languages);
        Text.writeString(dataOutput, poster_path);
        Text.writeString(dataOutput, cast);
        dataOutput.writeInt(cast_size);
        dataOutput.writeInt(crew_size);
        Text.writeString(dataOutput, director);

    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        id = Text.readString(dataInput);
        title = Text.readString(dataInput);
        tagline = Text.readString(dataInput);
        release_date = Text.readString(dataInput);
        genres = Text.readString(dataInput);
        belongs_to_collection = Text.readString(dataInput);
        original_language = Text.readString(dataInput);
        budget_musd = dataInput.readDouble();
        revenue_musd = dataInput.readDouble();
        production_companies = Text.readString(dataInput);
        production_countries = Text.readString(dataInput);
        vote_count = dataInput.readInt();
        vote_average = dataInput.readDouble();
        popularity = dataInput.readDouble();
        runtime = dataInput.readInt();
        overview = Text.readString(dataInput);
        spoken_languages = Text.readString(dataInput);
        poster_path = Text.readString(dataInput);
        cast = Text.readString(dataInput);
        cast_size = dataInput.readInt();
        crew_size = dataInput.readInt();
        director = Text.readString(dataInput);

    }

    @Override
    public int compareTo(MovieWritable o) {
        return Double.compare(this.vote_average, o.vote_average);
    }
}
